// pages/cooperation/com/com-card-template/com-card-template.js

let animation;
let callback;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    decorate: {
      type: Boolean,
      default: true
    }
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  },

  /**
   * 组件的初始数据
   */
  data: {
    animationData: {},
    count: 2,
  },

  lifetimes: {
    attached: function () {
      if (!animation) {
        animation = wx.createAnimation({
          timingFunction: "ease",
        });
      }
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    start(fn) {
      callback = fn;
      animation.translateX(500).rotate(25).step({duration: 600, timingFunction: 'ease-in'});
      this.setData({
        animationData: animation.export(),
      });
    },

    handleEnd() {
      if (callback) {
        callback && callback()
        callback = null

        setTimeout(() => {
          animation.translateX(0).rotate(0).step({duration: 10, timingFunction: 'step-start'});
          this.setData({
            animationData: animation.export(),
          });
        }, 100)
        
      } else {
        this.triggerEvent('onaniend')
      }
    }
  },
});
